let formatTime = function(t, option) {
  // 格式化时间
  var time = new Date(t)
  var y = time.getFullYear();
  var m = time.getMonth() + 1;
  var d = time.getDate();
  var h = time.getHours();
  var mm = time.getMinutes();
  m = m < 10 ? "0"+m: m;
  d = d < 10 ? "0"+d: d;
  h = h < 10 ? "0"+h: h;
  mm = mm < 10 ? "0"+mm: mm;
  var ft = y + "-" + m + "-" + d + " " + h + ":" + mm;
  console.log(ft);
  if(option){
    if(option == "day_start"){
      var rt = ft.split(' ')[0] + " 00:00:00";
      return rt;
    }else if(option == "day_end"){
      var rt = ft.split(' ')[0] + " 23:59:59";
      return rt;
    }else if(option == "month_start"){
      var rt = ft.split('-')[0] + '-' + time.split('-')[1] + "-01 00:00:00";
      return rt;
    }else if(option == "year_start"){
      var rt = ft.split('-')[0] + "01-01 00:00:00";
      return rt;
    }
  }else{
    return ft;
  }
}
let mydateFormat = function (time) {
  var t = new Date(time * 1000);
  var yy = t.getFullYear();
  var mm = t.getMonth() + 1;
  var dd = t.getDate();
  var h = t.getHours();
  var m = t.getMinutes();
  var s = t.getSeconds();
  // mm = mm < 10 ? "0" + mm : mm;
  // dd = dd < 10 ? "0" + dd : dd;
  h = h < 10 ? "0" + h : h;
  m = m < 10 ? "0" + m : m;
  s = s < 10 ? "0" + s : s;
  return  mm + "-" + dd + " " + h + ":" + m + ":" + s;
}
export { formatTime, mydateFormat};